package main

import "fmt"

/**
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, calculate the Hamming distance.

Note:
0 ≤ x, y < 231.

Example:

Input: x = 1, y = 4

Output: 2

Explanation:
1   (0 0 0 1)
4   (0 1 0 0)
       ↑   ↑

The above arrows point to positions where the corresponding bits are different.

“汉明距离”，一个较为著名的问题，给定两个整数，求出这两个数字的二进制中位数不同的个数。比如上面的1和4，在第0位和第2位数字不同，因此这个汉明距离就是2。
https://www.youtube.com/watch?v=RNaO23ETjhM
https://blog.csdn.net/styshoo/article/details/54099552

2进制轮训
对于整数%2，得到最后一位，然后再/2，消除最后一位，循环调用即可


*/

func main() {
	fmt.Println(hammingDistance(1, 4))
}

func hammingDistance(x int, y int) int {
	loop := 31

	count := 0
	for i := 0; i < loop; i++ {
		bx := x % 2
		by := y % 2
		if bx != by {
			count++
		}
		x = x / 2
		y = y / 2
	}

	return count
}
